package The_first_work;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomSelector {
    public static Group randomGroup(List<Group> groups) {
        Random random = new Random();
        int index = random.nextInt(groups.size());
        return groups.get(index);
    }

    public static Student randomStudentInGroup(List<Student> students, int groupId) {
        List<Student> groupStudents = new ArrayList<>();
        for (Student student : students) {
            if (student.getGroupId() == groupId) {
                groupStudents.add(student);
            }
        }
        Random random = new Random();
        if (groupStudents.isEmpty()) {
            return null;
        }
        int index = random.nextInt(groupStudents.size());
        return groupStudents.get(index);
    }

    public static Student randomStudentInClass(List<Student> students, int classId) {
        List<Student> classStudents = new ArrayList<>();
        for (Student student : students) {
            if (student.getClassId() == classId) {
                classStudents.add(student);
            }
        }
        Random random = new Random();
        if (classStudents.isEmpty()) {
            return null;
        }
        int index = random.nextInt(classStudents.size());
        return classStudents.get(index);
    }
}
